<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //定义异步路由
    let allAsyncRoute = [
        {
            name: 'Acl',
            children: [
                { name: 'role' },
                { name: 'auth' }
            ]
        },
        {
            name: 'Product',
            children: [
                { name: 'Trademark' },
                { name: 'Attr' },
                { name: 'Sku' },
                { name: 'Spu' }
            ]
        },
    ]
    let routes = ['Acl', "Product", 'role', 'Sku'];
        function findAsyncRoute(allAsyncRoute,routes){
            return allAsyncRoute.filter(item=>{
                if(routes.includes(item.name)){
                    if(item.children && item.children.length >0){
                        item.children=(item.children,routes)
                    }
                    return true
                }
            })
        }
        let result=findAsyncRoute(allAsyncRoute,routes)
  





    //     //递归练习
    // function findAsyncRoute(allAsyncRoute, routes) {
    //     //规律一级路由
    //     return allAsyncRoute.filter(item => {
    //         //判断一级路由名字在routes数组里面是否出现，如果出现过滤出来
    //         if (routes.includes(item.name)) {
    //             //过滤二、三、四级、五级...有没有子路由过滤出来
    //             if (item.children && item.children.length > 0) {
    //                 item.children = findAsyncRoute(item.children, routes);
    //             }
    //             return true;
    //         }
    //     })
    // }
    //最终想要过滤出来的异步路由：用户想要动态添加路由！！！！
    // let result = findAsyncRoute(allAsyncRoute, routes);





    </script>
</body>
</html>